package com.cdivtc.management.controller;

import com.cdivtc.management.pojo.*;
import com.cdivtc.management.service.TeacherTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/teacherAddTask")
public class TeacherAddTaskController {

    @Autowired
    private TeacherTaskService teacherTaskService;

    @RequestMapping("/add")
    public Result addTeacherTopic(TeaAddTaskParamBean teaAddTaskParamBean) {
        if (teaAddTaskParamBean.getTopicId() != null) {
            TeacherReleaseTask teacherReleaseTask = teacherTaskService.addTeaTask(teaAddTaskParamBean);
            if (teacherReleaseTask != null) {
                return new Result().ok().addData(teacherReleaseTask);
            } else {
                return new Result().error("添加失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }

    @RequestMapping("/update")
    public Result updTeacherTopic(TeaAddTaskParamBean teaAddTaskParamBean) {
        if (teaAddTaskParamBean.getTaskId() != null) {
            TeacherReleaseTask teacherReleaseTask = teacherTaskService.UpdTeaTask(teaAddTaskParamBean);
            if (teacherReleaseTask != null) {
                return new Result().ok().addData(teacherReleaseTask);
            } else {
                return new Result().error("添加失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
//        System.out.println("teaAddTaskParamBean = " + teaAddTaskParamBean);

    }

    @RequestMapping("/delete")
    public Result deleteTeacherTopic(TeacherReleaseTask tr) {
        System.out.println("tr = " + tr);
        if (tr.getId() != null) {
            TeacherReleaseTask teacherReleaseTask = teacherTaskService.delTeaTopic(tr);
            if (teacherReleaseTask != null) {
                return new Result().ok().addData(teacherReleaseTask);
            } else {
                return new Result().error("发布失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }

    @RequestMapping("/publish")
    public Result publishTeacherTopic(TeacherReleaseTask tr) {
        System.out.println("tr = " + tr);
        if (tr.getId() != null) {
            TeacherReleaseTask teacherReleaseTask = teacherTaskService.publishTeaTopic(tr);
            if (teacherReleaseTask != null) {
                return new Result().ok().addData(teacherReleaseTask);
            } else {
                return new Result().error("发布失败！！！");
            }
        } else {
            return new Result().error("数据为空");
        }
    }

    @RequestMapping("/select")
    public Result selAllTask(String teaId) {
        if (teaId != null) {
            List<Map<String, Object>> t = teacherTaskService.selAll(teaId);
            return new Result().ok().addData(t);
        } else
            return new Result().error("数据为空");

    }

}
